# step 1: look at the beg-of-lines
BEGIN{
  if(ARGV[2]=="key"){fsep="@";frege="^@";what="KEYWORD"};
  if(ARGV[2]=="opt"){fsep="-";frege="^-";what="OPTION"};
  if(ARGV[2]=="prag"){fsep="\\";frege="^\\\\";what="PRAGMA"};
  delete ARGV[2];
  ARGC--;
#  print fsep,frege,what;
  if(!fsep){err=1;exit}
}
$0 ~ frege {
  nk++;
  keywd[substr($1,2,length($1))]=1;
#  print $1;
}
# find ALL except first field
{
  tmp=substr($0,length($1+1),length($0));
  m=split(tmp,a,fsep);
  for(i=2;i<=m;i++){
    match(a[i],/^[[:alpha:]]*_?\.?[[:alpha:]]*/);
    nik++;kwintext[substr(a[i],RSTART,RLENGTH)]=1;
  }
}
END{
  if(err){
    print "Unrecognized ...";
    exit;
  };
  if(nk){
    print nk" "what"(S):"
      for(i in keywd){
	print i;
      } 
  }else{print "No "tolower(what)"s defined"}
  for(i in kwintext){
    if(!keywd[i]){nun++;kwintext[i]=0};
  }
  if(nun){
    print what"(S) that occured in the helpfile, but were not defined:"
      for(i in kwintext){
	if(!kwintext[i]){
	print i;
	}
      }
  }else if (nik){print "All "tolower(what)"s had their definition"}
}
